<?php
/**
 * 描述：会员注册-第一步。
 */
final class Exec_Account_Register_First extends Exec
{   
    public function Get()
    {
        View::Display('account/register/first.tpl');
    }
     
    public function Post()
    {
        #验证码
        $captcha=trim(Functions::FormArgs('Captcha_Register_First'));
        if(empty($captcha)||$captcha!=Session::Get(Account::SESSIONNAME_REGISTER_CAPTCHA))
        {
            echo 'Captcha';
            return false;
        }

        #获取参数
        $username=trim(Functions::FormArgs('Username_Register_First'));
        $password=trim(Functions::FormArgs('Password_Register_First'));
        $password_confirm=trim(Functions::FormArgs('Password_Confirm_Register_First'));
        
        #验证数据
        if(!Match::Email($username))
        {
            echo 'Username';
            return;
        }
        if(!Match::Password($password))
        {
            echo 'Password';
            return;
        }
        if($password!=$password_confirm)
        {
            echo 'Different';
            return;
        }

        #检测是否存在
        $account=new Account($username);
        {
            if($account->IsExists())
            {
                echo 'Exists';
                return;
            }
        }
        $account=null;

        #存储数据
        $data=array
        (
            'Username'=>$username,
            'Password'=>Account::EncryptPassword($password,$username)
        );
        Session::Set(Account::SESSIONNAME_REGISTERDATA,$data);

        #成功返回
        echo 'Success';
    }
}
?>